home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvtools
/
demos
/
surfdemo
/
surfdsp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-08
|
9KB
|
295 lines
#ifndef lint
static char SccsId[]= "@(#)surfdsp.c V1.11 3/17/95";
#endif
/*------------------------------------------------------------------
| file name -- display.c
|
| functions Description
| --------- -----------
| InitDisplay Initializes the SCREEN and DRAWPORTS
| TermDisplays Cleans up the SCREEN, DRAWPORTS and DISPLAY_LIST
|
| InitMainDrawport Initializes the main graph drawport
| InitControlDrawports Initializes the threshold and color control drawports
|
| DrawDisplays Draws the display
| DoPlot Draws just the graph
|
|-----------------------------------------------------------------*/
#include "std.h"
#include "dvstd.h"
#include "dvtools.h"
#include "VOstd.h"
#include "surfdata.h"
#include "dvtoolfuns.h"
#include "dvinteract.h"
#include "VOfundecl.h"
#include "VGfundecl.h"
#include "VPfundecl.h"
#include "VUfundecl.h"
#include "GRfundecl.h"
#include "surffundecl.h"
#define WINDOW_TITLE " *** DataViews Data Visualization Demo ***"
#define MAIN_VIEW "surfdemo.v"
#define PALETTE_VIEW "colors.v"
#define THRESH_VIEW "thresholds.v"
/***************** Begin Function Declarations *************/
LOCAL void InitMainDrawport V_P_((void));
/***************** End Function Declarations *************/
/*------------------------------------------------------------------
|
| InitDisplay
| This function opens the screen and creates the main and control
| drawports.
*/
void
InitDisplay (device)
char *device;
{
int error_code;
char buf[50];
/* Open the main window */
VUoff_copyright ();
Screen = TscOpenSet (device, (CHAR *) NULL,
V_WINDOW_NAME, WINDOW_TITLE,
#ifdef WINNT
/* V_WINDOW_HEIGHT, 600,
V_WINDOW_WIDTH, 800, */
V_WIN32_ICON_NAME, "surficon",
#endif /* WINNT */
V_X_EXPOSURE_BLOCK, YES,
V_ACTIVE_CURSOR,
V_END_OF_LIST);
if(!Screen)
{
error_code=TscOpenError();
#ifdef WINNT
sprintf(buf,"Product is not validated. Error code %d.",error_code);
MessageBox(NULL,buf,"Validation Error",MB_OK);
#else
fprintf(stderr,"Product is not validated. Error code %d.",error_code);
#endif
exit(error_code);
}
/* If we couldn't open a window, exit the program */
EXIT_IF_INVALID (Screen, NO_DEVICE);
/* Erase the "copyright" message */
(VOID) TscErase (Screen);
/* Load in the Main, Threshold and Palette views */
MainView = TviLoad (MAIN_VIEW);
EXIT_IF_INVALID (MainView, NO_MAIN_VIEW);
ThreshView = TviLoad (THRESH_VIEW);
EXIT_IF_INVALID (ThreshView, NO_THRESH_VIEW);
PaletteView = TviLoad (PALETTE_VIEW);
EXIT_IF_INVALID (PaletteView, NO_PALETTE_VIEW);
/* Create Drawports and Initialize global variables */
InitMainDrawport ();
InitControlDrawports ();
}
/*------------------------------------------------------------------
|
| InitMainDrawport
| This function creates a drawport for the main graph display
| and initializes special objects. The graphs must be extracted
| and their vdp's rebound. We also get the objects associated
| with the color threshold echo box and the formula echo box.
*/
LOCAL void InitMainDrawport
V_P_ ((void))
{
INT i;
VARDESC vdp;
/* Create the Drawport */
MainDrawport = TdpCreate (Screen, MainView,
(RECTANGLE *) NULL, (RECTANGLE *) NULL);
MainDrawing = TviGetDrawing (MainView);
/* Find the graph object and rebind its data */
GraphObj = TdrGetNamedObject (MainDrawing, "DisplayArea");
GraphDgp = VOdgGetDgp (GraphObj);
GraphVdp = GetVdp (GraphObj);
(VOID) TvdPutBuffer (GraphVdp, (ADDRESS) Formula.data);
/* Find the frame behind the graph */
FrameObj = TdrGetNamedObject (MainDrawing, "GraphFrame");
/* Find the timining meter graph and rebind its data */
TimingObj = TdrGetNamedObject (MainDrawing, "TimingArea");
(VOID) VOobReference (TimingObj);
TimingDgp = VOdgGetDgp (TimingObj);
TimingVdp = GetVdp (TimingObj);
(VOID) TvdPutBuffer (TimingVdp, (ADDRESS) & TimingValue);
/* Delete meter graph since it isn't part of the initial display */
(VOID) VOdrObDelete (MainDrawing, TimingObj);
/* Get the threshold table and set the initial threshold value */
VGvdctt (GraphVdp, &ThreshTableSize, &ThreshTable);
for (i = 0; i < 3; i++)
ThreshValue[i] = Formula.zmin +
(ThreshTable[i].upperlimit / (FLOAT) 32768) *
(Formula.zmax - Formula.zmin);
ThreshEchoArea = TdrGetNamedObject (MainDrawing, "ThresholdBox");
/* Find the FormulaArea */
FormulaArea = TdrGetNamedObject (MainDrawing, "FormulaArea");
/* Find the Message/Formula Text Object */
MessageObj = TdrGetNamedObject (MainDrawing, "FormulaText");
vdp = GetVdp (MessageObj);
(VOID) TvdPutBuffer (vdp, (ADDRESS) MessageBuf);
}
/*------------------------------------------------------------------
|
| InitControlDrawports
| This function creates drawports for the color and threshold
| controls. The drawports are created so they fit inside the
| graph. The drawports won't be drawn until the user requests
| the controls. This function is also called after the user
| resizes the window. The drawports must be recreated since the
| position of the graph has changed.
*/
void InitControlDrawports
V_P_ ((void))
{
OBJECT area_obj;
RECTANGLE where_vp, what_vp, dummy;
/* Setup the Threshold and Control Areas */
area_obj = TdrGetNamedObject (MainDrawing, "DisplayArea");
VOobBox (area_obj, &where_vp, &dummy);
(VOID) TdpWorldToScreen (MainDrawport, &where_vp.ll, &where_vp.ll);
(VOID) TdpWorldToScreen (MainDrawport, &where_vp.ur, &where_vp.ur);
(VOID) GRscs_to_vcs (&where_vp.ll, &where_vp.ll);
(VOID) GRscs_to_vcs (&where_vp.ur, &where_vp.ur);
/* Setup the Threshold Control Drawport */
ThreshDrawing = TviGetDrawing (ThreshView);
VOobBox (ThreshDrawing, &what_vp, &dummy);
if (ThreshDrawport)
(VOID) TdpResize (ThreshDrawport, &where_vp);
else
ThreshDrawport = TdpCreateStretch (Screen, ThreshView,
&where_vp, &what_vp);
/* Setup the Color Control Drawport */
PaletteDrawing = TviGetDrawing (PaletteView);
VOobBox (PaletteDrawing, &what_vp, &dummy);
if (PaletteDrawport)
(VOID) TdpResize (PaletteDrawport, &where_vp);
else
PaletteDrawport = TdpCreateStretch (Screen, PaletteView,
&where_vp, &what_vp);
}
/*------------------------------------------------------------------
|
| DrawDisplay
| This function draws the main drawport. If its the first time
| the drawport is drawn, the initialization message is displayed.
*/
void
DrawDisplay (first_time_flag)
BOOLPARAM first_time_flag;
{
if (first_time_flag == FIRST_TIME)
{
SetMessage ("Surfdemo -- V.I. Corporation");
(VOID) TdpDraw (MainDrawport);
DrawThreshRect (ThreshEchoArea);
PrintMessage (FormulaMenu[0], YES);
}
else
{
(VOID) TscRedraw (Screen, (RECTANGLE *) NULL);
DrawThreshRect (ThreshEchoArea);
}
}
/*------------------------------------------------------------------
|
| DoPlot
| This function draws the graph if needed. If new data is being
| generated, the timing meter is displayed. After the data is
| calculated, the graph is displayed.
*/
void DoPlot
V_P_ ((void))
{
/* Do data checking */
if (CheckPlotData ())
{
/* Erase the current plot */
(VOID) TdpEraseObject (MainDrawport, FrameObj);
(VOID) TdpEraseObject (MainDrawport, GraphObj);
/* See if we need to get new data */
if (NeedToGenData ())
{
/* Set up the timing meter */
if (Plot.xdivisions * Plot.ydivisions != 1)
VPvd_irange (TimingVdp, 1, (INT) (Plot.xdivisions * Plot.ydivisions));
else
VPvd_irange (TimingVdp, 1, 2);
(VOID) VOdrObAdd (TviGetDrawing (MainView), TimingObj);
TimingValue = 1.0;
(VOID) TdpDrawObject (MainDrawport, TimingObj);
/* Generate data, get rid of timing meter, and do new plot */
GenerateData (0);
(VOID) TdpEraseObject (MainDrawport, TimingObj);
(VOID) VOdrObDelete (TviGetDrawing (MainView), TimingObj);
}
/* Draw the graph */
(VOID) TdpDrawObject (MainDrawport, FrameObj);
(VOID) TdpDrawObject (MainDrawport, GraphObj);
}
}
/*------------------------------------------------------------------
|
| TermDisplays
| This function cleans up the views, drawports and closes the
| screen.
*/
void TermDisplays
V_P_ ((void))
{
/* Cleanup the Drawports and Views */
(VOID) TdpDestroy (MainDrawport);
(VOID) TviDestroy (MainView);
(VOID) TdpDestroy (ThreshDrawport);
(VOID) TviDestroy (ThreshView);
(VOID) TdpDestroy (PaletteDrawport);
(VOID) TviDestroy (PaletteView);
/* Cleanup the window */
(VOID) TscErase (Screen);
(VOID) TscClose (Screen);
}